import { useState } from "react"; import { KeyboardAvoidingView, Pressable, View } from "react-native"; import { useSafeAreaInsets } from "react-native-safe-area-context"; import { Stack, useLocalSearchParams, useRouter } from "expo-router"; import BookmarkAssetView from "@/components/bookmarks/BookmarkAssetView"; import BookmarkLinkTypeSelector, { BookmarkLinkType, } from "@/components/bookmarks/BookmarkLinkTypeSelector"; import BookmarkLinkView from "@/components/bookmarks/BookmarkLinkView"; import BookmarkTextView from "@/components/bookmarks/BookmarkTextView"; import BottomActions from "@/components/bookmarks/BottomActions"; import FullPageError from "@/components/FullPageError"; import FullPageSpinner from "@/components/ui/FullPageSpinner"; import useAppSettings from "@/lib/settings"; import { useQuery } from "@tanstack/react-query"; import { Settings } from "lucide-react-native"; import { useColorScheme } from "nativewind"; import { useTRPC } from "@karakeep/shared-react/trpc"; import { BookmarkTypes } from "@karakeep/shared/types/bookmarks"; export default function BookmarkView() { const insets = useSafeAreaInsets(); const router = useRouter(); const { slug } = useLocalSearchParams(); const { colorScheme } = useColorScheme(); const isDark = colorScheme === "dark"; const { settings } = useAppSettings(); const api = useTRPC(); const [bookmarkLinkType, setBookmarkLinkType] = useState( settings.defaultBookmarkView, ); if (typeof slug !== "string") { throw new Error("Unexpected param type"); } const { data: bookmark, error, refetch, } = useQuery( api.bookmarks.getBookmark.queryOptions({ bookmarkId: slug, includeContent: false, }), ); if (error) { return ; } if (!bookmark) { return ; } let comp; let title = null; switch (bookmark.content.type) { case BookmarkTypes.LINK: title = bookmark.title ?? bookmark.content.title; comp = ( ); break; case BookmarkTypes.TEXT: title = bookmark.title; comp = ; break; case BookmarkTypes.ASSET: title = bookmark.title ?? bookmark.content.fileName; comp = ; break; } return ( bookmark.content.type === BookmarkTypes.LINK ? ( {bookmarkLinkType === "reader" && ( router.push("/dashboard/settings/reader-settings") } > )} setBookmarkLinkType(type)} bookmark={bookmark} /> ) : undefined, }} /> {comp} ); }